/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sun.scheduler.util.graph.algorithm.maxflow;

import sun.scheduler.util.graph.BFSIterator;
import sun.scheduler.util.graph.Edge;
import sun.scheduler.util.graph.Node;

/**
 * A BFSIterator for the {@link ResidualGraph} that ignores edges that have a 
 * residual capacity of zero.
 * @see BFSIterator
 * @see ResidualGraph
 * @author mfj
 */
public class ResidualBFSIterator extends BFSIterator<Label, ResidualEdgeData>
{
    /**
     * The precision with which double values are compared.
     */
    public final double precision;
    
    /**
     * Instantiates a new {@link ResidualBFSIterator} from the given {@link ResidualGraph}
     * and the specified precision for double value comparisson
     * @param graph the 
     * @param precision 
     */
    public ResidualBFSIterator(ResidualGraph graph, double precision)
    {
        super(graph);
        this.precision = precision;
    }

    public ResidualBFSIterator(Node<Label, ResidualEdgeData> start, double precision)
    {
        super(start);
        this.precision = precision;
    }

    /**
     * {@inheritedDoc }. It also ignores all edges with residual capacity of zero.
     * {@code Math.abs(edge.getData()) < precision}.
     */
    @Override
    protected boolean ignore(Edge<Label, ResidualEdgeData> edge)
    {
        return Math.abs(edge.getData().getResidualCapacity()) < precision || super.ignore(edge);
    }
}
